package cn.org.donald.base;

import java.io.Serializable;

/**
 * @author : Donald
 * @since : 2021/3/16 16:38
 */
public class HttpResult<T> implements Serializable {


    private static final long serialVersionUID = 1L;

    private Integer code;

    private String info;

    private Long timestamp = System.currentTimeMillis();

    private T data;


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public static HttpResult success(String info) {
        return baseResult(200,info);
    }

    public static HttpResult success(Integer code, String info) {
        return baseResult(code,info);
    }

    public static HttpResult fail(String info) {
        return baseResult(500,info);
    }

    public static HttpResult fail(Integer code, String info) {
        return baseResult(code,info);
    }


    private static <T> HttpResult<T> baseResult(Integer code, String info) {
        HttpResult<T> result = new HttpResult<>();
        result.setCode(code);
        result.setInfo(info);
        return result;
    }
}
